<template>
  <BaseForm v-model="formDataModel" @close="$emit('callBack')" />

</template>

<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import StaffInfoApi from '/@/api/webPath/StaffInfoApi.ts';
import { translate } from "/@/i18n";
import FORM_FIELD_TYPE from "/@/constants/FormFieldType.ts";
import { useEnumList } from '~/src/utils/useEnumList';
defineOptions({
  name: 'StaffInfoEdit',
})
const props = defineProps({
  modelValue: {

  }
})
const emit = defineEmits(['fetch-data', 'callBack'])

const formRef = ref<FormInstance>();
const title = ref<string>('');
const dialogFormVisible = ref<boolean>(false);
const staffSexEnumList = useEnumList("SexType")
const staffSeparationStatusList = useEnumList("StaffStatus")



const formDataModel = ref({
  columnCount: 1,
  expandLimit: 6,
  autoFit: false,
  columnWidth: '300px',
  labelPosition: 'right',
  labelWidth: '120px',
  modelData: {},  //表单参数值 初始化
  callback: async (any: object) => {  //表单执行成功后回调
    //完成数据提交
    const { message } = await StaffInfoApi.save(any)
    $baseMessage(message, 'success', 'vab-hey-message-success');
    dialogFormVisible.value = false


    //事件及数据推送到上一层父类
    emit('callBack', any); //把表单数据推送到上一层
  },
  items: [  //表单item数据初始化
    {
      label: "人员姓名",
      field: "staffName",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      // rule: {
      //   required: true,
      //   trigger: 'blur',
      //   validator: (rule: any, value: any, callback: any) => {  //绑定验证
      //     callback();
      //   },
      // },
      rule: [{
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      {
        required: true,
        message: "请输入姓名"
      }
      ]

    },

    {
      label: "性别",
      field: "staffSexName",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
      // config: {
      options: [
        {
          value: '女',
          label: "女"
        },
        {
          value: '男',
          label: "男"
        },
        {
          value: '未知',
          label: "未知"
        },
      ],

      // },
      // options: staffSexEnumList,
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "出生日期",
      field: "staffBirthDate",
      clearable: true,
      type: FORM_FIELD_TYPE.DATE,
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

      config: {
        props: {   //日期精度配置
          type: "daterange",
          startPlaceholder: "开始日期",
          endPlaceholder: "结束日期",
          format: "YYYY-MM-DD",
        }
      },
    },
    {
      label: "身份证号",
      field: "staffIdentity",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      // rule: {
      //   required: true,
      //   trigger: 'blur',
      //   validator: (rule: any, value: any, callback: any) => {  //绑定验证
      //     callback();
      //   },
      // },

      rule: [{
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      {
        required: true,
        message: "请输入身份证号"
      }
      ]
    },
    {
      label: "职位",
      field: "staffPosition",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
    },
    {
      label: "入职日期",
      field: "staffEntryDate",
      clearable: true,
      type: FORM_FIELD_TYPE.DATE,
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

      config: {
        props: {   //日期精度配置
          type: "daterange",
          startPlaceholder: "开始日期",
          endPlaceholder: "结束日期",
          format: "YYYY-MM-DD",
        }
      },
    },
    {
      label: "健康证号",
      field: "healthCertificateCode",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      // rule: {
      //   required: true,
      //   trigger: 'blur',
      //   validator: (rule: any, value: any, callback: any) => {  //绑定验证
      //     callback();
      //   },
      // },
      rule: [{
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      {
        required: true,
        message: "请输入身份证号"
      }
      ]

    },
    // {
    //   label: "健康证",
    //   field: "healthCertificateUrl",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.UPLOAD,
    //   config: {
    //     type: "file"
    //   },

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    {
      label: "健康证",
      field: "healthCertificateUrl",
      clearable: true,
      type: FORM_FIELD_TYPE.UPLOAD,
      config: {
        limit: 1
      },
      placeholder: "请输入",
      rule: {
        required: true,
        trigger: 'blur',
        message: '健康证图片不能为空'
      },
    },
    {
      label: "健康证有效期",
      field: "healthCertificateDate",
      clearable: true,
      type: FORM_FIELD_TYPE.DATE,
      placeholder: "请输入",
      // rule: {
      //   required: true,
      //   trigger: 'blur',
      //   validator: (rule: any, value: any, callback: any) => {  //绑定验证
      //     callback();
      //   },
      // },
      rule: [{
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      {
        required: true,
        message: "请填写身份证有效期"
      }
      ],

      config: {
        props: {   //日期精度配置
          type: "daterange",
          startPlaceholder: "开始日期",
          endPlaceholder: "结束日期",
          format: "YYYY-MM-DD",
        }
      },
    },
    // {
    //   label: "所属公司",
    //   field: "companyName",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    // {
    //   label: "是否离职",
    //   field: "status",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
    //   options: [
    //     {
    //       value: 0,
    //       label: "在职"
    //     },
    //     {
    //       value: 1,
    //       label: "离职"
    //     },
    //   ],
    //   // options: staffSeparationStatusList

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    //   {
    //     label: "排序",
    //     field: "sort",
    //     clearable: true,
    //     type: FORM_FIELD_TYPE.INPUTNUMBER,
    //     defaultValue: 0,

    //    placeholder:"请输入",

    //    rule:{
    //      trigger: 'blur',
    //      validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //            callback();
    //        },
    //      },

    // },

  ],
})






//页面数据加载
onMounted(async () => {

  //初始化数据model
  if (props.modelValue.query) { //跳转过来时候有参数
    if (props.modelValue.query.staffInfoId) {  //id存在则为编辑，加载网络数据，如上级页面带参数手动覆盖

      const { data } = await StaffInfoApi.getDetail({
        staffInfoId: props.modelValue.query.staffInfoId   //从路由中获取参数
      })
      formDataModel.value.modelData = data;
    } else {
      //新增时候则用父类页面传参默认填充可根据业务修改
      for (const key in props.modelValue.query) {
        formDataModel.value.modelData[key] = props.modelValue.query[key]
      }
    }
  }
})


//方法暴露区域  todo
defineExpose({

})

</script>
